<template>
  <div>
    <van-dialog
      @confirm="confirm"
      v-model="$store.state.showDialog"
      :title="dialogTitle"
    >
      <div style="max-height: 50vh; overflow-y: scroll">
        <div v-if="isEmpty">
          <van-cell> 暂无搜索结果，换一个搜索试试 </van-cell>
        </div>
        <div v-else>
          <van-list>
            <van-cell
              v-for="(item, index) in list"
              :key="index"
              :title="item | toString"
              @click="copyWord(`${item}`)"
            />
          </van-list>
        </div>
      </div>
    </van-dialog>
  </div>
</template>

<script>
import { copyWord } from "../utils/copy";
import { mapGetters } from "vuex";
import { Empty } from "vant";

export default {
  props: {
    list: {
      type: Object,
    },
  },
  data() {
    return {};
  },
  computed: {
    isEmpty() {
      if (this.list == null) {
        return true;
      } else {
        return Object.keys(this.list).length == 0;
      }
      console.log(this.list);
      // console.log(Object.keys(this.list).length)
    },
    ...mapGetters(["dialogTitle"]),
  },

  filters: {
    toString(val) {
      return val.toString();
    },
  },
  methods: {
    confirm() {
      this.$store.commit("setShowDialog", false);
    },
    copyWord(words) {
      return copyWord(words);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>